<div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <%= link_to "Huginn", root_path, :class => 'navbar-brand' %>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  
  <% if user_signed_in? %>
    <ul class='nav navbar-nav'>
      <%= nav_link "Agents", agents_path do %>
        <ul class='dropdown-menu' role='menu'>
          <%= nav_link icon_tag('glyphicon-plus') + " New Agent", new_agent_path %>
          <%= nav_link icon_tag('glyphicon-refresh') + " Run event propagation", propagate_agents_path, method: 'post' %>
          <%= nav_link icon_tag('glyphicon-random') + " View Diagram", diagram_path %>
        </ul>
      <% end %>
      <%= nav_link "Scenarios", scenarios_path %>
      <%= nav_link "Events", events_path %>
      <%= nav_link "Credentials", user_credentials_path %>
      <%= nav_link "Services", services_path %>
    </ul>
  <% end %>
  
  <ul class="nav navbar-nav navbar-right">
    <% if user_signed_in? %>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" id='agent-navigate' autocomplete="off" placeholder="Search">
          <%= image_tag "spinner-arrows.gif", :class => "spinner" %>
        </div>
      </form>
      
      <li class='job-indicator' role='pending'>
        <%= link_to current_user.admin? ? jobs_path : '#' do %>
          <span class="badge"><%= icon_tag('glyphicon-refresh', class: 'icon-white') %> <span class='number'>0</span></span>
        <% end %>
      </li>
      <li class='job-indicator' role='awaiting_retry'>
        <%= link_to current_user.admin? ? jobs_path : '#' do %>
          <span class="badge"><%= icon_tag('glyphicon-question-sign', class: 'icon-yellow') %> <span class='number'>0</span></span>
        <% end %>
      </li>
      <li class='job-indicator' role='recent_failures'>
        <%= link_to current_user.admin? ? jobs_path : '#', class: 'hidden-sm hidden-xs' do %>
        <span class="badge"><%= icon_tag('glyphicon-exclamation-sign', class: 'icon-white') %> <span class='number'>0</span></span>
        <% end %>
      </li>
      <li id='event-indicator'>
        <a href="#" class='hidden-sm hidden-xs'>
          <span class="badge"><%= icon_tag('glyphicon-random', class: 'icon-white') %> <span class='number'>0</span> events</span>
        </a>
      </li>
    <% end %>
    
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">
        Account
        <% if user_signed_in? && session[:original_admin_user_id].present? %>
          <span class="label label-warning"><%= current_user.username %></span>
        <% end %>
        <b class="caret"></b>
      </a>
      <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
        <% if user_signed_in? && session[:original_admin_user_id].present? %>
          <li>
            <%= link_to 'Switch Back to Admin User', switch_back_admin_users_path, tabindex: '-1' %>
          </li>
        <% end %>
        <li>
          <% if user_signed_in? %>
            <%= link_to 'Account', edit_user_registration_path, :tabindex => "-1" %>
          <% else %>
            <%= link_to 'Sign up', new_user_registration_path, :tabindex => "-1" %>
          <% end %>
        </li>
        <% if user_signed_in? && current_user.admin %>
          <li>
            <%= link_to 'Job Management', jobs_path, :tabindex => '-1' %>
          </li>
          <li>
            <%= link_to 'User Management', admin_users_path, tabindex: '-1' %>
          </li>
        <% end %>
        <li>
          <%= link_to 'About', 'https://github.com/huginn/huginn', :tabindex => "-1" %>
        </li>

        <li>
          <% if user_signed_in? %>
            <%= link_to 'Logout', destroy_user_session_path, :method => :delete, :tabindex => "-1" %>
          <% else %>
            <%= link_to 'Login', new_user_session_path, :tabindex => "-1" %>
          <% end %>
        </li>
      </ul>
    </li>

  </ul>
</div>
